@scrider/formatter 1.4.2 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +99 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -1
- package/dist/index.d.ts +36 -1
- package/dist/index.js +90 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -39,13 +39,19 @@ __export(index_exports, {
|
|
|
39
39
|
LINE_HEIGHT_BLOCK_TAGS: () => LINE_HEIGHT_BLOCK_TAGS,
|
|
40
40
|
NODE_TYPE: () => NODE_TYPE,
|
|
41
41
|
NodeDOMAdapter: () => NodeDOMAdapter,
|
|
42
|
+
PARAGRAPH_SPACING_BLOCK_TAGS: () => PARAGRAPH_SPACING_BLOCK_TAGS,
|
|
42
43
|
Registry: () => Registry,
|
|
43
44
|
SCRIDER_LINE_HEIGHT_KEY: () => SCRIDER_LINE_HEIGHT_KEY,
|
|
45
|
+
SCRIDER_MARGIN_AFTER_KEY: () => SCRIDER_MARGIN_AFTER_KEY,
|
|
46
|
+
SCRIDER_MARGIN_BEFORE_KEY: () => SCRIDER_MARGIN_BEFORE_KEY,
|
|
44
47
|
alertBlockHandler: () => alertBlockHandler,
|
|
45
48
|
alignFormat: () => alignFormat,
|
|
46
49
|
backgroundFormat: () => backgroundFormat,
|
|
47
50
|
blockFormat: () => blockFormat,
|
|
48
51
|
blockLineHeightStyleParts: () => blockLineHeightStyleParts,
|
|
52
|
+
blockMarginAfterStyleParts: () => blockMarginAfterStyleParts,
|
|
53
|
+
blockMarginBeforeStyleParts: () => blockMarginBeforeStyleParts,
|
|
54
|
+
blockParagraphMarginStyleParts: () => blockParagraphMarginStyleParts,
|
|
49
55
|
blockPresentationStyleParts: () => blockPresentationStyleParts,
|
|
50
56
|
blockquoteFormat: () => blockquoteFormat,
|
|
51
57
|
boldFormat: () => boldFormat,
|
|
@@ -98,6 +104,9 @@ __export(index_exports, {
|
|
|
98
104
|
nodeAdapter: () => nodeAdapter,
|
|
99
105
|
normalizeDelta: () => normalizeDelta,
|
|
100
106
|
parseScriderLineHeightMultiplier: () => parseScriderLineHeightMultiplier,
|
|
107
|
+
parseScriderMarginAfterEm: () => parseScriderMarginAfterEm,
|
|
108
|
+
parseScriderMarginBeforeEm: () => parseScriderMarginBeforeEm,
|
|
109
|
+
parseScriderMarginEm: () => parseScriderMarginEm,
|
|
101
110
|
preloadRemark: () => preloadRemark,
|
|
102
111
|
resolveDocumentPresentation: () => resolveDocumentPresentation,
|
|
103
112
|
resolveTablePresentation: () => resolveTablePresentation,
|
|
@@ -2610,7 +2619,10 @@ function slugifyWithDedup(text, usedSlugs) {
|
|
|
2610
2619
|
|
|
2611
2620
|
// src/conversion/html/block-presentation.ts
|
|
2612
2621
|
var SCRIDER_LINE_HEIGHT_KEY = "scrider-line-height";
|
|
2622
|
+
var SCRIDER_MARGIN_AFTER_KEY = "scrider-margin-after";
|
|
2623
|
+
var SCRIDER_MARGIN_BEFORE_KEY = "scrider-margin-before";
|
|
2613
2624
|
var LINE_HEIGHT_BLOCK_TAGS = /* @__PURE__ */ new Set(["p", "li", "blockquote"]);
|
|
2625
|
+
var PARAGRAPH_SPACING_BLOCK_TAGS = /* @__PURE__ */ new Set(["p"]);
|
|
2614
2626
|
function parseScriderLineHeightMultiplier(value) {
|
|
2615
2627
|
const trimmed = value.trim();
|
|
2616
2628
|
if (!trimmed) return void 0;
|
|
@@ -2639,6 +2651,73 @@ function blockLineHeightStyleParts(tag, blockAttributes, resolved) {
|
|
|
2639
2651
|
}
|
|
2640
2652
|
return [];
|
|
2641
2653
|
}
|
|
2654
|
+
function parseScriderMarginEm(value) {
|
|
2655
|
+
const trimmed = value.trim();
|
|
2656
|
+
if (!trimmed) return void 0;
|
|
2657
|
+
const emMatch = trimmed.match(/^(-?\d+(?:\.\d+)?)\s*em$/i);
|
|
2658
|
+
if (emMatch) {
|
|
2659
|
+
const n2 = Number.parseFloat(emMatch[1]);
|
|
2660
|
+
if (Number.isFinite(n2) && n2 >= 0) return n2;
|
|
2661
|
+
return void 0;
|
|
2662
|
+
}
|
|
2663
|
+
const n = Number.parseFloat(trimmed);
|
|
2664
|
+
if (Number.isFinite(n) && n >= 0) return n;
|
|
2665
|
+
return void 0;
|
|
2666
|
+
}
|
|
2667
|
+
var parseScriderMarginAfterEm = parseScriderMarginEm;
|
|
2668
|
+
var parseScriderMarginBeforeEm = parseScriderMarginEm;
|
|
2669
|
+
function resolveParagraphMarginEm(blockAttributes, blockKey, documentEm) {
|
|
2670
|
+
const raw = blockAttributes?.[blockKey];
|
|
2671
|
+
if (typeof raw === "string") {
|
|
2672
|
+
const fromBlock = parseScriderMarginEm(raw);
|
|
2673
|
+
if (fromBlock !== void 0) return fromBlock;
|
|
2674
|
+
}
|
|
2675
|
+
return documentEm;
|
|
2676
|
+
}
|
|
2677
|
+
function blockParagraphMarginStyleParts(tag, blockAttributes, resolved) {
|
|
2678
|
+
if (!PARAGRAPH_SPACING_BLOCK_TAGS.has(tag)) return [];
|
|
2679
|
+
const marginTop = resolveParagraphMarginEm(
|
|
2680
|
+
blockAttributes,
|
|
2681
|
+
SCRIDER_MARGIN_BEFORE_KEY,
|
|
2682
|
+
resolved?.paragraphSpacingBeforeEm
|
|
2683
|
+
);
|
|
2684
|
+
const marginBottom = resolveParagraphMarginEm(
|
|
2685
|
+
blockAttributes,
|
|
2686
|
+
SCRIDER_MARGIN_AFTER_KEY,
|
|
2687
|
+
resolved?.paragraphSpacingAfterEm
|
|
2688
|
+
);
|
|
2689
|
+
if (marginTop === void 0 && marginBottom === void 0) return [];
|
|
2690
|
+
const parts = [];
|
|
2691
|
+
if (marginTop !== void 0) {
|
|
2692
|
+
parts.push(`margin-top:${marginTop}em`);
|
|
2693
|
+
} else if (marginBottom !== void 0) {
|
|
2694
|
+
parts.push("margin-top:0");
|
|
2695
|
+
}
|
|
2696
|
+
if (marginBottom !== void 0) {
|
|
2697
|
+
parts.push(`margin-bottom:${marginBottom}em`);
|
|
2698
|
+
}
|
|
2699
|
+
return parts;
|
|
2700
|
+
}
|
|
2701
|
+
function blockMarginAfterStyleParts(tag, blockAttributes, resolved) {
|
|
2702
|
+
if (!PARAGRAPH_SPACING_BLOCK_TAGS.has(tag)) return [];
|
|
2703
|
+
const marginBottom = resolveParagraphMarginEm(
|
|
2704
|
+
blockAttributes,
|
|
2705
|
+
SCRIDER_MARGIN_AFTER_KEY,
|
|
2706
|
+
resolved?.paragraphSpacingAfterEm
|
|
2707
|
+
);
|
|
2708
|
+
if (marginBottom === void 0) return [];
|
|
2709
|
+
return ["margin-top:0", `margin-bottom:${marginBottom}em`];
|
|
2710
|
+
}
|
|
2711
|
+
function blockMarginBeforeStyleParts(tag, blockAttributes, resolved) {
|
|
2712
|
+
if (!PARAGRAPH_SPACING_BLOCK_TAGS.has(tag)) return [];
|
|
2713
|
+
const marginTop = resolveParagraphMarginEm(
|
|
2714
|
+
blockAttributes,
|
|
2715
|
+
SCRIDER_MARGIN_BEFORE_KEY,
|
|
2716
|
+
resolved?.paragraphSpacingBeforeEm
|
|
2717
|
+
);
|
|
2718
|
+
if (marginTop === void 0) return [];
|
|
2719
|
+
return [`margin-top:${marginTop}em`];
|
|
2720
|
+
}
|
|
2642
2721
|
|
|
2643
2722
|
// src/conversion/html/document-presentation.ts
|
|
2644
2723
|
function resolveDocumentPresentation(presentation) {
|
|
@@ -2646,10 +2725,18 @@ function resolveDocumentPresentation(presentation) {
|
|
|
2646
2725
|
const lineSpacing = typeof presentation.lineSpacing === "number" && presentation.lineSpacing > 0 ? presentation.lineSpacing : void 0;
|
|
2647
2726
|
const textIndentCm = typeof presentation.textIndentCm === "number" && presentation.textIndentCm > 0 ? presentation.textIndentCm : void 0;
|
|
2648
2727
|
const listBlockIndentCm = typeof presentation.listBlockIndentCm === "number" && presentation.listBlockIndentCm > 0 ? presentation.listBlockIndentCm : void 0;
|
|
2649
|
-
|
|
2728
|
+
const paragraphSpacingAfterEm = typeof presentation.paragraphSpacingAfterEm === "number" && Number.isFinite(presentation.paragraphSpacingAfterEm) && presentation.paragraphSpacingAfterEm >= 0 ? presentation.paragraphSpacingAfterEm : void 0;
|
|
2729
|
+
const paragraphSpacingBeforeEm = typeof presentation.paragraphSpacingBeforeEm === "number" && Number.isFinite(presentation.paragraphSpacingBeforeEm) && presentation.paragraphSpacingBeforeEm >= 0 ? presentation.paragraphSpacingBeforeEm : void 0;
|
|
2730
|
+
if (lineSpacing === void 0 && paragraphSpacingAfterEm === void 0 && paragraphSpacingBeforeEm === void 0 && textIndentCm === void 0 && listBlockIndentCm === void 0) {
|
|
2650
2731
|
return void 0;
|
|
2651
2732
|
}
|
|
2652
|
-
return {
|
|
2733
|
+
return {
|
|
2734
|
+
lineSpacing,
|
|
2735
|
+
paragraphSpacingAfterEm,
|
|
2736
|
+
paragraphSpacingBeforeEm,
|
|
2737
|
+
textIndentCm,
|
|
2738
|
+
listBlockIndentCm
|
|
2739
|
+
};
|
|
2653
2740
|
}
|
|
2654
2741
|
var TEXT_INDENT_TAGS = /* @__PURE__ */ new Set(["p"]);
|
|
2655
2742
|
function documentPresentationListWrapperStyleParts(resolved) {
|
|
@@ -2667,6 +2754,7 @@ function documentPresentationStyleParts(tag, resolved) {
|
|
|
2667
2754
|
function blockPresentationStyleParts(tag, blockAttributes, resolved) {
|
|
2668
2755
|
return [
|
|
2669
2756
|
...blockLineHeightStyleParts(tag, blockAttributes, resolved),
|
|
2757
|
+
...blockParagraphMarginStyleParts(tag, blockAttributes, resolved),
|
|
2670
2758
|
...documentPresentationStyleParts(tag, resolved)
|
|
2671
2759
|
];
|
|
2672
2760
|
}
|
|
@@ -5302,13 +5390,19 @@ function extractTableRegion(ops, hintOpIdx) {
|
|
|
5302
5390
|
LINE_HEIGHT_BLOCK_TAGS,
|
|
5303
5391
|
NODE_TYPE,
|
|
5304
5392
|
NodeDOMAdapter,
|
|
5393
|
+
PARAGRAPH_SPACING_BLOCK_TAGS,
|
|
5305
5394
|
Registry,
|
|
5306
5395
|
SCRIDER_LINE_HEIGHT_KEY,
|
|
5396
|
+
SCRIDER_MARGIN_AFTER_KEY,
|
|
5397
|
+
SCRIDER_MARGIN_BEFORE_KEY,
|
|
5307
5398
|
alertBlockHandler,
|
|
5308
5399
|
alignFormat,
|
|
5309
5400
|
backgroundFormat,
|
|
5310
5401
|
blockFormat,
|
|
5311
5402
|
blockLineHeightStyleParts,
|
|
5403
|
+
blockMarginAfterStyleParts,
|
|
5404
|
+
blockMarginBeforeStyleParts,
|
|
5405
|
+
blockParagraphMarginStyleParts,
|
|
5312
5406
|
blockPresentationStyleParts,
|
|
5313
5407
|
blockquoteFormat,
|
|
5314
5408
|
boldFormat,
|
|
@@ -5361,6 +5455,9 @@ function extractTableRegion(ops, hintOpIdx) {
|
|
|
5361
5455
|
nodeAdapter,
|
|
5362
5456
|
normalizeDelta,
|
|
5363
5457
|
parseScriderLineHeightMultiplier,
|
|
5458
|
+
parseScriderMarginAfterEm,
|
|
5459
|
+
parseScriderMarginBeforeEm,
|
|
5460
|
+
parseScriderMarginEm,
|
|
5364
5461
|
preloadRemark,
|
|
5365
5462
|
resolveDocumentPresentation,
|
|
5366
5463
|
resolveTablePresentation,
|